﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public abstract class SlotObject : MonoBehaviour
{
    public Slot slot;
    // Start is called before the first frame update
    protected void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public virtual bool Move(int dx, int dy, float duration = 0.3f)
    {
        transform.DOMove(transform.position + new Vector3(dx, dy, 0) * slot.gridManager.SquareSize, duration);
        slot.SlotState = Slot.State.empty;
        slot.SlotObject = null;
        slot = slot.GetNewSlot(dx, dy);
        slot.SlotObject = this;
        transform.SetParent(slot.transform);
        return true;
    }

    public void PureMove(int dx, int dy, float duration = 0.3f)
    {
        transform.DOMove(transform.position + new Vector3(dx, dy, 0) * slot.gridManager.SquareSize, duration);
        slot.SlotObject = null;
        slot = slot.GetNewSlot(dx, dy);
        slot.SlotObject = this;
        transform.SetParent(slot.transform);
    }

    public abstract bool OnPlayerTouch(Player player, int dx = 0, int dy = 0);
}
